﻿
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>基础信息</legend>
    </fieldset>
    <script type='text/html' template lay-done='layui.data.formdone(d.params);'>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}" />
        <input type='hidden' name='BasicAttributes' id="BasicAttributes" value='{{ d.params.BasicAttributes || '' }}' />
    </script>
    <input type='hidden' name='Specs' />
    <input type='hidden' name='Params' />
    <div class='layui-form-item'>
        <label class='layui-form-label'>所属分类</label>
        <div class='layui-input-inline' style="width:705px;">
            <div class='layui-input-inline' style="width:705px;">
                <script type='text/html' template>
                    <input type='text' name='GoodsCategoryID_SelSourceName' value='{{ d.params.GoodsCategoryID_SelSourceName || '' }}' lay-verify='required' placeholder='所属分类' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>名称</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='Name' value='{{ d.params.Name || '' }}' lay-verify='required' placeholder='名称' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>货号</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='ArtNo' value='{{ d.params.ArtNo || '' }}' lay-verify='required' placeholder='货号' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>副标题</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='Title' value='{{ d.params.Title || '' }}' lay-verify='' placeholder='副标题' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>检索关键字</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='KeyWords' value='{{ d.params.KeyWords || '' }}' lay-verify='' placeholder='搜索关键字,如背包,旅行箱(逗号隔开)' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>供应商</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='SupplierID_SelSourceName' value='{{ d.params.SupplierID_SelSourceName || '' }}' lay-verify='' placeholder='供应商' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>商品介绍图</label>
        <div class='layui-input-inline' style="width:80%">
            <div class="layui-upload">
                <div class="layui-upload-list" id="divImgs"></div>
                <script type='text/html' template lay-done='layui.data.setUploads(d.params);'>
                    <input type="hidden" name="Images" id="Images" value="{{ d.params.Images || '' }}">
                </script>
                <hr />
            </div>
        </div>
    </div>
    <!--<div class='layui-form-item'>
        <label class='layui-form-label'>价格</label>
        <div class='layui-input-inline' style="width:705px;">
            <script type='text/html' template>
                <input type='text' name='Price' value='{{ d.params.Price || '' }}' lay-verify='required|number' placeholder='价格' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>-->

    <fieldset class="layui-elem-field layui-field-title">
        <legend>销售信息</legend>
    </fieldset>
    <div class='layui-form-item'>
        <div style="margin-bottom:10px;">
            <label class='layui-form-label'>规格</label>
            <div class='layui-input-inline' style="width:200px;">
                <script type='text/html' template>
                    <input type='text' name='SpecMode' id="SpecMode" value='{{ d.params.SpecMode || '' }}' lay-verify='required' placeholder='规格' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <label class='layui-form-label'>重量(kg)</label>
            <div class='layui-input-inline' style="width:120px;">
                <script type='text/html' template>
                    <input type='text' name='Weight' id="Weight" value='{{ d.params.Weight || '' }}' lay-verify='required|number' placeholder='重量' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <label class='layui-form-label'>初始库存</label>
            <div class='layui-input-inline' style="width:120px;">
                <script type='text/html' template>
                    <input type='text' name='Stock' id="Stock" value='{{ d.params.Stock || '' }}' lay-verify='required|number' placeholder='初始库存' autocomplete='off' class='layui-input'>
                </script>
            </div>
        </div>
    </div>
    <div class='layui-form-item'>
        <div style="margin-bottom:10px;">
            <label class='layui-form-label'>配送方式</label>
            <div class='layui-input-inline' style="width:200px;">
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"DeliveMode");'>
                    <select name='DeliveMode' xm-select="DeliveMode" id='DeliveMode' lay-verify='required' disabled>
                        <option value=""></option>
                    </select>
                </script>
            </div>
            <label class='layui-form-label'>是否包邮</label>
            <div class='layui-input-inline' style="width:120px;">
                <script type='text/html' template>
                    <select id="IsShipping_Sel" name="IsShipping_Sel" lay-verify='required' lay-filter="IsShip" disabled>
                        <option value='0' {{ d.params.IsShipping_Sel == '0' ? 'selected' : '' }}>不包邮</option>
                        <option value='1' {{ d.params.IsShipping_Sel == '1' ? 'selected' : '' }}>包邮</option>
                    </select>
                </script>
            </div>
            <label class='layui-form-label'>限购数量</label>
            <div class='layui-input-inline' style="width:120px;">
                <script type='text/html' template>
                    <input type='text' name='LimitNum' id="LimitNum" value='{{ d.params.LimitNum || '0' }}' lay-verify='required|number' placeholder='限购数量' autocomplete='off' class='layui-input'>
                </script>
            </div>
            <span style="color:green">默认0，表示无限制</span>
        </div>
    </div>
    <div class='layui-form-item' id="divFreight">
        <label class='layui-form-label'>运费模板</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <input type='text' name='FreightName' value='{{ d.params.FreightName || '' }}' lay-verify='' placeholder='运费模板' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>限购区域</label>
        <div class='layui-input-inline' style="width:350px;">
            <script type='text/html' template>
                <input type='text' name='LimitArea' value='{{ d.params.LimitArea || '' }}' lay-verify='' placeholder='限购区域' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
            商品-会员价格
        </legend>
    </fieldset>
    <div class='layui-form-item'>
        <label class='layui-form-label'>商品价格</label>
        <div class='layui-input-inline' style="width:100px;">
            <script type='text/html' template>
                <input type='text' name='Price' id="Price" value='{{ d.params.Price || '' }}' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>
            </script>
        </div>
        <label class='layui-form-label'>结算价格</label>
        <div class='layui-input-inline' style="width:100px;">
            <script type='text/html' template>
                <input type='text' name='Price1' id="Price1" value='{{ d.params.Price1 || '' }}' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>
            </script>
        </div>
        <span style="color:green">供应商结算价格</span>
    </div>
    <div id="divLevels">
    </div>

    <fieldset class="layui-elem-field layui-field-title">
        <legend>详细信息</legend>
    </fieldset>
    <div class='layui-form-item'>
        <label class='layui-form-label'>产品详情</label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                {{ d.params.Content_Edit || '' }}
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>售后说明</label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                {{ d.params.Aftersalest_Edit || '' }}
            </script>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>创建人</label>
        <div class='layui-input-inline' style="margin-top:7px">
            <script type='text/html' template>
                {{ d.params.CreateUserName || '' }}
            </script>
        </div>
        <label class='layui-form-label'>创建时间</label>
        <div class='layui-input-inline' style="margin-top:7px">
            <script type='text/html' template>
                {{ d.params.CreateTime || '' }}
            </script>
        </div>
    </div>
    <div class='layui-form-item'>
        <label class='layui-form-label'>最后编辑人</label>
        <div class='layui-input-inline' style="margin-top:7px">
            <script type='text/html' template>
                {{ d.params.UpdateUserName || '' }}
            </script>
        </div>
        <label class='layui-form-label'>最后编辑时间</label>
        <div class='layui-input-inline' style="margin-top:7px">
            <script type='text/html' template>
                {{ d.params.UpdateTime || '' }}
            </script>
        </div>
    </div>
</div>
<style>
    .layui-upload-img {
        width: 100px;
        height: auto;
        margin-left:3px
    }

    .input2 {
        width: 20px;
        height: 18px;
        position: absolute;
        bottom: 0px;
        background-color: rgba(56, 56, 56, 0.82);
        border: rgba(56, 56, 56, 0.82);
        color: white;
        text-align: center;
    }
</style>
<script type="text/javascript">

    layui.use(['form', 'admin'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var admin = layui.admin;
        var $ = layui.$;

        form.on("select(IsShip)", function (data) {
            LoadFeight(data.value);
        })

    });

    var Brand = "";
    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['form', 'admin', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;

            if (sourceName == "DeliveMode") {
                var formSelects = layui.formSelects;
                formSelects.config('DeliveMode', {
                    keyName: 'Text',            //自定义返回数据中name的key, 默认 name
                    keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
                });
                layui.formSelects.data('DeliveMode',
                    'local',
                    {
                        arr: [{ 'Text': '自提', 'PID': '0' }, { 'Text': '快递', 'PID': '1' }],//要把自己的这个节点去掉
                    });

                var selIDs = d.DeliveMode;
                if (selIDs != "" && selIDs != undefined) {
                    for (var i = 0; i < selIDs.split(',').length; i++) {
                        formSelects.value('DeliveMode', [selIDs.split(',')[i]], true);
                    }
                }
                //formSelects.value('DeliveMode', []);
            }
        });
    }

    var ImgNum = 0;
    var Images = [];
    layui.data.setUploads = function (d) {
        layui.use(['jquery', 'upload', 'admin'], function () {
            window.jQuery = window.$ = layui.jquery;
            upload = layui.upload,
                admin = layui.admin;

            var pics = d.Images;
            if (pics != "" && pics != null && pics != 'null') {
                //var s = pics.replace(/&quot;/g, '"');
                var strs = JSON.parse(pics);
                for (var i = 0; i < strs.length; i++) {
                    var str = strs[i];
                    if (str != "") {
                        addImg({ name: str, path: layui.setter.ImgPath + str });
                    }
                }
            }
        })
    }
    function addImg(src) {
        var div = "divimg" + ImgNum;
        var img = "Img" + ImgNum;
        var html = "    <div style=\"line-height:100px;float:left\" id='" + div + "'> " +
                           " <img id='" + img + "' src=\"" + src.path + "\"   alt=\"\" class=\"layui-upload-img\">" +
                       "</div>";
        $('#divImgs').append(html);

        var image = {};
        image["src"] = src.name;
        image["xh"] = ImgNum;
        Images.push(image);

        var strs = [];
        $.each(Images, function (i, d) {
            var str = d.src;
            strs.push(str);
        })

        $("#Images").val(JSON.stringify(strs));
        ImgNum++;
    }

    layui.data.datedone = function (d) {
        layui.use('laydate', function () {
            var laydate = layui.laydate;

        });
    }
    
    var StockNum = 1;
    var Stocks = [];
    var MenmberLevels = [];
    layui.data.formdone = function (d) {
        //debugger;
        LoadMemberPrice(d.PID);

        //是否包邮 显示运费模板选项
        if (d.IsShipping_Sel == "" || d.IsShipping_Sel == null) {
            LoadFeight(0);
        } else {
            LoadFeight(d.IsShipping_Sel);
        }
        if (d.DeliveMode != "" && d.DeliveMode != null && d.DeliveMode.indexOf("1") >= 0) {
            LoadShip(1, d.IsShipping_Sel);
        } else {
            LoadShip(0);
        }
    }



    //加载会员价格
    function LoadMemberPrice(GoodID) {
        var $ = layui.$;
        var form = layui.form;
        var admin = layui.admin;

        admin.req({
            url: layui.setter.APIUrl + '/shop/Goods_memberpriceMgr/getLevels?GoodID=' + GoodID, //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                var data = res.Data;
                MenmberLevels = data;
                var html = "";
                $.each(data, function (i, d) {
                    var levelstr = d.LevelStr;
                    var levelid = "Level" + d.Level;
                    var price = d.Price;
                    if (price == null || price == 0) {
                        price = "";
                    }
                    var showid = "IsShow" + d.Level;
                    var checked = "";
                    if (d.IsShow == 1) {
                        checked = "checked";
                    }
                    html += "" +
                        "<div class='layui-form-item'>" +
                        "  <label class='layui-form-label'>" + levelstr + "</label>" +
                        "  <div class='layui-input-inline' style=\"width:100px;\">" +
                        "          <input type='text' id='" + levelid + "' value='" + price + "' lay-verify='required|number' placeholder='' autocomplete='off' class='layui-input'>" +
                        "  </div>" +
                        "  <div class='layui-input-inline'>" +
                        "      <input type='checkbox' id='" + showid + "' " + checked + " lay-skin='switch' lay-text=\"展示|不展示\" disabled>" +
                        "  </div>" +
                        "</div>";
                });
                $("#divLevels").html(html);
                form.render();
            }
        });
    }
    //获取会员价格
    function GetMemberPrice() {
        var $ = layui.$;
        for (var i = 0; i < MenmberLevels.length; i++) {
            var levelid = "Level" + MenmberLevels[i].Level;
            var showid = "IsShow" + MenmberLevels[i].Level;
            var price = $("#" + levelid + "").val();
            MenmberLevels[i].IsShow = 0;
            if ($('#' + showid).is(':checked')) {
                MenmberLevels[i].IsShow = 1;
            }
            MenmberLevels[i].Price = price;
        }
        var res = JSON.stringify(MenmberLevels);
        return res;
    }

    function LoadShip(iskd, isship) {
        if (iskd == 1) {
            $("#divShip").show();
            if (isship == 1) {
                LoadFeight(1);
            } else {
                LoadFeight(0);
            }
        } else {
            $("#divShip").hide();
            LoadFeight(1);
        }
    }

    function LoadFeight(IsShip) {
        if (IsShip == 0) {
            $("#divFreight").show();
        } else {
            $("#divFreight").hide();
        }
    }


    //function Return() {
    //    location.href = "/Admin/start/index.html#" + "/shop/shop_Goods_Base/Index";
    //}
</script>